package cn.wolfcode.luowowo.mgrsite.controller;

import cn.wolfcode.luowowo.article.domain.Destination;
import cn.wolfcode.luowowo.article.query.DestinationQuery;
import cn.wolfcode.luowowo.article.service.IDestinationService;
import cn.wolfcode.luowowo.common.util.AjaxResult;
import com.alibaba.dubbo.config.annotation.Reference;
import com.github.pagehelper.PageInfo;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.List;

@Controller
@RequestMapping("/destination")
public class DestinationController {
    @Reference
    private IDestinationService destinationService;

    @RequestMapping("/list")
    public String destination(Model model,@ModelAttribute("qo") DestinationQuery qo){
        PageInfo pageInfo = destinationService.query(qo);
        model.addAttribute("pageInfo",pageInfo);
        List<Destination> toasts = destinationService.getToasts(qo.getParentId());
        model.addAttribute("toasts",toasts);
        return "/destination/list";
    }

    @ResponseBody
    @RequestMapping("/changeHotValue")
    public Object changeHotValue(boolean hot,Long id){
        destinationService.updateHotValue(hot,id);
        return AjaxResult.SUCCESS;
    }

    @ResponseBody
    @RequestMapping("/setInfo")
    public AjaxResult Update(String info,Long id){
        try {
            destinationService.setInfo(info,id);
        }catch (Exception e){
            e.printStackTrace();
            return new AjaxResult(false,e.getMessage());
        }
        return new AjaxResult(true,"保存成功");
    }

}
